package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.pojo.Friend;
import java.util.List;

import com.example.vo.UserFriend;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface FriendMapper extends BaseMapper<Friend> {

    // 根据user_id查询好友列表
    @Select("SELECT distinct * FROM friend f JOIN user u ON (f.user_id1 = u.user_id OR f.user_id2 = u.user_id) " +
            "WHERE (f.user_id1 = #{userId} OR f.user_id2 = #{userId}) AND f.status = '已接受' ORDER BY f.friend_id")
    List<UserFriend> findByUserId(@Param("userId") Long userId);


    @Select("SELECT distinct * FROM friend JOIN user ON " +
            "WHERE friend.status = '已接受' ORDER BY friend.friend_id")
    List<UserFriend> selectAllFriends();
}
